package com.googlecode.jawb.clues.types;

/**
 * Interface for custom converter without direct access to the input stream. It
 * is preferred to use this converter over the {@link StaticLengthType}
 * converter, because it is much safer.
 * 
 * @see #fromByteArray(byte[])
 * @see #getAcceptedLength()
 * @see #toByteArray(Object)
 */
public interface StaticLengthType {
	/**
	 * Constructs object from given array of bytes (length of that array is
	 * given by {@link #getAcceptedLength()}.
	 * 
	 * @param rawBytes
	 *            Array of bytes to construct object from.
	 * @return Constructed object.
	 */
	public Object fromByteArray(byte[] rawBytes);
	
	/**
	 * Specifies requested amount of bytes to construct a object. This method is
	 * called before the {@link #fromByteArray(byte[])} and loaded array of
	 * bytes will have exactly the same length as what the value returned by
	 * this method.
	 * 
	 * @return Requested amount of bytes to construct an object.
	 */
	public int getAcceptedLength();
	
	/**
	 * Converts object to an array of bytes.
	 * 
	 * @param object
	 *            Object to be converted.
	 * @return Array of bytes to be saved into the output stream.
	 */
	public byte[] toByteArray(Object object);
}
